package cn.wolfcode.qo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultPage<T> {
    private int currentPage;
    private int pageSize;
    private int totalPage;
    private int totalCount;
    private int prePage;
    private int nextPage;
    private List<T> data;

    public ResultPage(int currentPage,int pageSize) {
        new ArrayList<>();
    }

    public ResultPage(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        prePage = currentPage - 1 >= 1 ? currentPage - 1 : 1;
        nextPage = currentPage + 1 <= totalPage ? currentPage + 1 : totalPage;
    }
}
